//
//  AirAddBtnViewController.m
//  IPTV
//
//  Created by liao Echo on 14-1-4.
//  Copyright (c) 2014年 Echo. All rights reserved.
//

#import "AirAddBtnViewController.h"

@interface AirAddBtnViewController ()

@end

@implementation AirAddBtnViewController
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    int left = 40;
    int width = 50;
    for (int i=0; i<4; i++) {
        GoodBtn *btn = [GoodBtn btnWithFont:12];
        [btn setBackgroundImage:[IMG(@"ac_mode_unsel.png") stretchableImageWithLeftCapWidth:88/4 topCapHeight:50/4] forState:UIControlStateNormal];
        btn.frame = CGRectMake(left+i*(width+10), 100, width, 30);
        btn.tag = i;
        if (i == 0) {
            [btn setTitleColor:RGB(155, 220, 0, 1) forState:UIControlStateNormal];
            [btn setTitle:STR(@"制热") forState:UIControlStateNormal];
            if ([Global curLanguageEn]) {
                [btn setTitle:@"HEAT" forState:UIControlStateNormal];
            }
        }else if (i == 1) {
            [btn setTitle:STR(@"制冷") forState:UIControlStateNormal];
            if ([Global curLanguageEn]) {
                [btn setTitle:@"COOL" forState:UIControlStateNormal];
            }
        }else if (i == 2) {
            [btn setTitle:STR(@"除湿") forState:UIControlStateNormal];
            if ([Global curLanguageEn]) {
                [btn setTitle:@"DRY" forState:UIControlStateNormal];
            }
        }else if (i == 3) {
            [btn setTitle:STR(@"换气") forState:UIControlStateNormal];
            if ([Global curLanguageEn]) {
                [btn setTitle:@"Ventilation" forState:UIControlStateNormal];
            }
        }
        [self.view addSubview:btn];
        [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
	
    GoodBtn *btn = [GoodBtn btnWithFont:12];
    [btn setBackgroundImage:[IMG(@"ac_mode_unsel.png") stretchableImageWithLeftCapWidth:88/4 topCapHeight:50/4] forState:UIControlStateNormal];
    btn.frame = CGRectMake(left, 100+40, width, 30);
    btn.tag = 4;
    [btn setTitle:STR(@"自动") forState:UIControlStateNormal];
    if ([Global curLanguageEn]) {
        [btn setTitle:@"AUTO" forState:UIControlStateNormal];
    }
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem textBarButtonItem:STR(@"保存") target:self action:@selector(savebtnPressed)];
    
    [self initPicker];
    
    
//    GoodBtn *savebtn = [GoodBtn btnWithFont:12];
//    [savebtn setBackgroundImage:[IMG(@"ac_mode_unsel.png") stretchableImageWithLeftCapWidth:88/4 topCapHeight:50/4] forState:UIControlStateNormal];
//    savebtn.frame = CGRectMake(SCREEN_WIDTH-100, SCREEN_HEIGHT-200, width, 30);
//    [savebtn setTitle:STR(@"保存") forState:UIControlStateNormal];
//    [self.view addSubview:savebtn];
//    [savebtn addTarget:self action:@selector(savebtnPressed) forControlEvents:UIControlEventTouchUpInside];
}
-(void)btnPressed:(UIButton*)btn{
    btn_tag = btn.tag;
    for (int i=0; i<[self.view subviews].count; i++) {
        GoodBtn *view = [[self.view subviews] objectAtIndex:i];
        if ([view isKindOfClass:[GoodBtn class]]) {
            [view setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
    }
    [btn setTitleColor:RGB(155, 220, 0, 1) forState:UIControlStateNormal];
}
-(void)savebtnPressed{
    [delegate editEd:btn_tag select:selectIndex];
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)initPicker{
    picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, FH(self.view)-100-64-50, 0, 100)];
    if (IOS7_OR_LATER) {
        picker.backgroundColor = [UIColor grayColor];
    }
    picker.delegate = self;
    picker.dataSource = self;
    picker.showsSelectionIndicator = YES;
    [self.view addSubview:picker];
    
    CGFloat bgviewY= FY(picker)-44;
    bgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, bgviewY, SCREEN_WIDTH, 44)];
    bgview.userInteractionEnabled = YES;
    bgview.image = [UIImage imageNamed:@"popping_bg.png"];
    
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, SCREEN_WIDTH, 19)];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = STR(@"请选择温度时间(单位度)");
    if ([Global curLanguageEn]) {
        label.text = @"Please choose temperature";
    }
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont boldSystemFontOfSize:14];
    label.backgroundColor = [UIColor clearColor];
    [bgview addSubview:label];
    
    [self.view addSubview:bgview];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return 15;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

#pragma UIPickerView Delegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [NSString stringWithFormat:@"%d", row+16];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    selectIndex = row;
}

@end
